//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.hentica.app.component.photo;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.WindowManager.LayoutParams;
import android.widget.TextView;

import com.example.empty.photo3.R;

import java.util.List;

public class TakePhotoDialog extends DialogFragment implements PhotoManager.PhotoCallBack {
    private View view;
    private PhotoGetBack callBack;
    private PhotoManager photoManager;
    private Activity activity;
    private boolean isCrop;
    private boolean isComproess;
    String content1;
    String content2;
    private TextView txt1;
    private TextView txt2;
    private TextView txt3;

    public TakePhotoDialog() {
    }

    public static TakePhotoDialog createDialog(Activity activity, String content1, String content2, PhotoGetBack callBack) {
        TakePhotoDialog makePhotoDialog2 = new TakePhotoDialog();
        makePhotoDialog2.content1 = content1;
        makePhotoDialog2.content2 = content2;
        makePhotoDialog2.callBack = callBack;
        makePhotoDialog2.activity = activity;
        return makePhotoDialog2;
    }

    public static TakePhotoDialog createDialog(Activity activity, boolean isComproess, boolean isCrop, String content1, String content2, PhotoGetBack callBack) {
        TakePhotoDialog makePhotoDialog2 = new TakePhotoDialog();
        makePhotoDialog2.content1 = content1;
        makePhotoDialog2.content2 = content2;
        makePhotoDialog2.callBack = callBack;
        makePhotoDialog2.activity = activity;
        makePhotoDialog2.isComproess = isComproess;
        makePhotoDialog2.isCrop = isCrop;
        return makePhotoDialog2;
    }

    public static TakePhotoDialog createDialog(Activity activity, PhotoManager photoManager, String content1, String content2, PhotoGetBack callBack) {
        TakePhotoDialog makePhotoDialog2 = new TakePhotoDialog();
        makePhotoDialog2.content1 = content1;
        makePhotoDialog2.content2 = content2;
        makePhotoDialog2.callBack = callBack;
        makePhotoDialog2.activity = activity;
        makePhotoDialog2.photoManager = photoManager;
        return makePhotoDialog2;
    }

    @Nullable
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        this.view = inflater.inflate(R.layout.dialog_bottom_two_item, container, false);
        return this.view;
    }

    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        if (this.photoManager == null) {
            this.photoManager = new PhotoManager();
        }

        this.photoManager.setPhotoCallBack(this);
        this.initView();
        this.setEvent();
    }

    public Dialog onCreateDialog(Bundle savedInstanceState) {
        this.setStyle(0, R.style.bottom_up_dialog);
        Dialog dialog = super.onCreateDialog(savedInstanceState);
        Window dialogWindow = dialog.getWindow();
        LayoutParams lp = dialogWindow.getAttributes();
        lp.height = DpUtils.dp2px(this.getContext(), 165);
        lp.width = DpUtils.screnWidth();
        dialogWindow.getDecorView().setPadding(0, 0, 0, 0);
        dialogWindow.setGravity(80);
        dialogWindow.setAttributes(lp);
        return dialog;
    }

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.d("takephoto", "onActivityResult");
        this.photoManager.handleActivityResult(requestCode, resultCode, data);
    }

    private void initView() {
        this.txt1 = (TextView)this.view.findViewById(R.id.dialog_first_item);
        this.txt2 = (TextView)this.view.findViewById(R.id.dialog_second_item);
        this.txt3 = (TextView)this.view.findViewById(R.id.dialog_cancel_btn);
        this.txt1.setText(this.content1);
        this.txt2.setText(this.content2);
    }

    private void setEvent() {
        this.view.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                TakePhotoDialog.this.dismiss();
            }
        });
        this.txt1.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                TakePhotoDialog.this.camera();
            }
        });
        this.txt2.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
                TakePhotoDialog.this.selectPhoto();
            }
        });
        this.txt3.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                TakePhotoDialog.this.dismiss();
            }
        });
    }

    private void selectPhoto() {
        CropOption option = new CropOption();
        option.aspectX = 1;
        option.aspectY = 1;
        this.photoManager.setCrop(this.isCrop).setOption(option).setCompross(this.isComproess).selectPic(this, this.activity);
    }

    private void camera() {
        CropOption option = new CropOption();
        option.aspectX = 1;
        option.aspectY = 1;
        this.photoManager.setCompross(this.isComproess).setCrop(this.isCrop).setOption(option).camera(this, this.activity);
    }

    public void getPhotos(List<String> photos) {
        if (this.callBack != null) {
            this.callBack.getPhotos(photos);
        }

    }

    public void error() {
        if (this.callBack != null) {
            this.callBack.error();
        }

    }

    public void dismissDialog() {
        this.dismiss();
    }
}
